﻿using AntdUI;
using Super.Admin.Utils.EventAggregator;
using Super.Admin.Utils.EventAggregator.EventType;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Super.Admin.Views.Page.MenuManagement
{
    public partial class MenuManagementModifyShowIcon : UserControl
    {
        public MenuManagementModifyShowIcon()
        {
            InitializeComponent();
            this.Load += MenuManagementModifyShowIcon_Load;
        }

        private void MenuManagementModifyShowIcon_Load(object? sender, EventArgs e)
        {
            PnlIcon.Controls.Clear();
            foreach (var icon in SvgDb.Custom.Keys)
            {
                if (!icon.Contains("Admin")) continue;
                var b = SvgDb.Custom.TryGetValue(icon, out var p);
                if (b)
                {
                    AntdUI.Button btn = new AntdUI.Button
                    {
                        IconSvg = p,
                        Text = "",
                        Size = new Size(40, 40),
                        Ghost = true,
                        IconRatio = 1,
                        WaveSize = 0
                    };
                    btn.Click += Btn_Click;
                    PnlIcon.Controls.Add(btn);
                }
            }
        }

        private void Btn_Click(object? sender, EventArgs e)
        {
            AntdUI.Button btn = (AntdUI.Button)sender;
            EventAggregator.Default.Publish<MenuIconEvent>(new MenuIconEvent { IconSvg = btn.IconSvg });
            Dispose();
        }
    }
}
